package Graphique;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;

import Command.Command;
import Command.CommandReset;
import Command.CommandSearch;
import Listener.ButtonListener;
import StaticValues.StaticTabs;

;

/**
 * @author tangi
 *
 */
/**
 * @author tangi
 * 
 */
public class ExpandedSearch {

	private ExpandBar expandSearch;
	private ExpandItem expandSearchItemFilm;
	private Combo comboGenre, comboYear;
	private Text textRecherche;
	private Composite compositeSearch;
	private Button rechercherFilm, retablir;
	private Label textFilm, textGenre, textYear;
	private GridLayout textSearchLayout;
	private GridData textSearchData;
	private Command commandSearch, commandReset;

	public ExpandedSearch(Composite c, int style) {
		expandSearch = new ExpandBar(c, style);
		initComponent();
	}

	private void initComponent() {

		textSearchLayout = new GridLayout(2, false);
		textSearchLayout.horizontalSpacing = 0;
		textSearchLayout.verticalSpacing = 10;

		textSearchData = new GridData();
		textSearchData.minimumWidth = 150;
		textSearchData.grabExcessHorizontalSpace = true;
		textSearchData.horizontalSpan = 5;

		compositeSearch = new Composite(expandSearch, SWT.None);
		compositeSearch.setLayout(textSearchLayout);
		compositeSearch.setToolTipText("coucou");

		textFilm = new Label(compositeSearch, SWT.NONE);
		textFilm.setText("Nom du film :");
		textRecherche = new Text(compositeSearch, SWT.SINGLE);
		textRecherche.setLayoutData(textSearchData);

		textGenre = new Label(compositeSearch, SWT.NONE);
		textGenre.setText("Genre: ");
		comboGenre = new Combo(compositeSearch, SWT.BORDER | SWT.READ_ONLY);
		comboGenre.setItems(StaticTabs.GENRES);

		textYear = new Label(compositeSearch, SWT.NONE);
		textYear.setText("Année : ");
		comboYear = new Combo(compositeSearch, SWT.READ_ONLY | SWT.DROP_DOWN);
		comboYear.setItems(StaticTabs.YEARS);

		rechercherFilm = new Button(compositeSearch, SWT.PUSH);
		rechercherFilm.setText("Rechercher");

		retablir = new Button(compositeSearch, SWT.PUSH);
		retablir.setText("Rétablir");

		expandSearchItemFilm = new ExpandItem(expandSearch, SWT.NONE);
		expandSearchItemFilm.setControl(compositeSearch);
		expandSearchItemFilm.setHeight(compositeSearch.computeSize(SWT.DEFAULT,
				SWT.DEFAULT).y);
		expandSearchItemFilm.setText("Options de recherche avancée");

		
		// Ajout des commandes et des listener associé
		commandSearch = new CommandSearch((CompositeList) expandSearch.getParent());
		commandSearch.setExpandSearch(this);
		rechercherFilm.addListener(SWT.Selection, new Listener() {

			@Override
			public void handleEvent(Event arg0) {
				commandSearch.execute();
			}
		});

		commandReset = new CommandReset((CompositeList) expandSearch.getParent());
		commandReset.setExpandSearch(this);
		retablir.addListener(SWT.Selection, new Listener() {

			@Override
			public void handleEvent(Event arg0) {
				commandReset.execute();
			}
		});

	}

	/**
	 * @return the retablir
	 */
	public Button getRetablir() {
		return retablir;
	}

	/**
	 * @return the comboGenre
	 */
	public Combo getComboGenre() {
		return comboGenre;
	}

	/**
	 * @return the comboYear
	 */
	public Combo getComboYear() {
		return comboYear;
	}

	/**
	 * @return the rechercherFilm
	 */
	public Button getRechercherFilm() {
		return rechercherFilm;
	}

	/**
	 * @return the textRecherche
	 */
	public Text getTextRecherche() {
		return textRecherche;
	}
	
	/**
	 * 
	 * @return
	 */
	public int getGenreFilm() {
		// TODO Auto-generated method stub
		return this.comboGenre.getSelectionIndex();
	}
	
	/**
	 * 
	 * @return
	 */
	public String getNameFilm() {
		return textRecherche.getText().trim();
	}
	
	/**
	 * 
	 * @return
	 */
	public int getYearFilm() {
		return this.comboYear.getSelectionIndex();
	}

}